import {
  createNavigationContainerRef,
  StackActions,
} from '@react-navigation/native';

export const navigationRef = createNavigationContainerRef();

export function navigate(name, params) {
  if (navigationRef.isReady()) {
    navigationRef.navigate(name, params);
  }
}

export function push(name, params) {
  if (navigationRef.isReady()) {
    const pushAction = StackActions.push(name, params);
    navigationRef.dispatch(pushAction);
  }
}

export function getBack() {
  if (navigationRef.isReady()) {
    navigationRef.goBack();
  }
}

export function getState() {
  if (navigationRef.isReady()) {
    return navigationRef.getState();
  }
}
